lane :beta do
    tag = `git describe --tags --abbrev=0 --match builds/beta/\*`.chomp
    changelog = File.read('changelog.txt') + `git shortlog #{tag}..HEAD`

    build_number = latest_testflight_build_number + 1
    increment_build_number(build_number: build_number)
    commit_version_bump(
        xcodeproj: 'iSH.xcodeproj',
        message: "Release build #{build_number} to testflight",
        include: "fastlane/changelog.txt",
        force: true,
    )

    build_app(project: 'iSH.xcodeproj')
    upload_to_testflight(
        changelog: changelog,
        wait_for_uploaded_build: true,
        distribute_external: true,
        groups: ["People"]
    )

    add_git_tag
    push_to_git_remote
    slack(
        message: "New build available!",
        default_payloads: [],
        payload: {
            "Changelog" => changelog
        },
     )
end
